package com.bank.trade_records.qu_money.service.impl;


import com.bank.trade_records.cun_money.entity.CunMoney;
import com.bank.trade_records.qu_money.dao.QuMoneyDao;
import com.bank.trade_records.qu_money.entity.QuMoney;
import com.bank.trade_records.qu_money.service.QuMoneyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class QuMoneyServiceImpl implements QuMoneyService {

    @Autowired
    private QuMoneyDao quMoneyDao;

    @Override
    public QuMoney getQuMoneyById(Long id) {
        return quMoneyDao.selectById(id);
    }

    @Override
    @Transactional
    public boolean addQuMoney(QuMoney QuMoney) {
        return quMoneyDao.insert(QuMoney) > 0;
    }

    @Override
    @Transactional
    public boolean updateQuMoney(QuMoney QuMoney) {
        return quMoneyDao.updateById(QuMoney) > 0;
    }

    @Override
    @Transactional
    public boolean deleteQuMoneyById(Long id) {
        return quMoneyDao.deleteById(id) > 0;
    }

    @Override
    public List<QuMoney> getAllQuMoneys() {
        return quMoneyDao.selectList(null);
    }

    @Override
    @Transactional
    public boolean batchInsert(List<QuMoney> quMoneyList) {
        return quMoneyDao.insertBatchSomeColumn(quMoneyList) > 0; // MyBatis-Plus提供了批量插入的方法
    }

    @Override
    public Page<QuMoney> getQuMoneyPage(Page<QuMoney> QuMoneyPage) {
        return quMoneyDao.selectPage(QuMoneyPage, null);
    }

    public List<QuMoney> getQuMoneyListByAccountId(long accountId){
        QueryWrapper<QuMoney> quMoneyQueryWrapper=new QueryWrapper<>();
        quMoneyQueryWrapper.eq("account_id", accountId);
        return quMoneyDao.selectList(quMoneyQueryWrapper);
    }
    public List<Object> getDailyTransactionAmounts() {
        List<Map<String, Object>> daoResult = quMoneyDao.getDailyTransactionAmounts();
        System.out.println(daoResult);
        List<Object> totalAmounts = new ArrayList<>();
        totalAmounts.add("取款记录");
        for (Map<String, Object> map : daoResult) {
            Double totalAmount = (Double) map.get("total_amount");
            totalAmounts.add(totalAmount);
        }

        return totalAmounts;
    }


}